home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mntlib43 / mntlib / tcpgrp.c < prev    next >
C/C++ Source or Header  |  1993-10-11  |  1KB  |  64 lines

  1. /*
  2. Public domain termios tc[get|set]pgrp() for the MiNT library
  3. 10 October 1993 entropy@terminator.rs.itd.umich.edu -- first attempt
  4. */
  5.  
  6. #include <mintbind.h>
  7. #include <types.h>
  8. #include <errno.h>
  9. #include <limits.h>
  10. #include <file.h>
  11. #include <ioctl.h>
  12. #include <unistd.h>
  13. #include <termios.h>
  14.  
  15. pid_t
  16. tcgetpgrp(fd)
  17.   int fd;
  18. {
  19.   long pg;
  20.   long r;
  21.  
  22.   r = Fcntl((short) fd, (long) &pg, TIOCGPGRP);
  23.   if (r < 0) {
  24.     errno = (int) -r;
  25.     return -1;
  26.   }
  27. #if 0
  28.   /* IEEE Std. 1003.1-1990: if there is no foreground process group, return
  29.      a value greater than 1 that does not match an existing process group.
  30.   */
  31.   while ((pg == 0) || (r != -ENOENT)) {
  32.     for (pg = 2; pg < INT_MAX; pg++) {
  33.       r = Pkill((short) -pg, 0);
  34.       if (r == -ENOENT)
  35.         break;
  36.     }
  37.   }
  38. #else
  39.   /* Sigh.  Some programs (notably bash) rely on this giving an error. */
  40.   if (pg == 0) {
  41.     errno = ENOENT;
  42.     return -1;
  43.   }
  44. #endif
  45.   return (pid_t) pg;
  46. }
  47.  
  48. int
  49. tcsetpgrp(fd, pgrp)
  50.   int fd;
  51.   pid_t pgrp;
  52. {
  53.   long r;
  54.   long pg;
  55.  
  56.   pg = (long) pgrp;
  57.   r = Fcntl((short) fd, (long) &pg, TIOCSPGRP);
  58.   if (r < 0) {
  59.     errno = (int) -r;
  60.     return -1;
  61.   }
  62.   return 0;
  63. }
  64.